from zentao_test.base.base_operation import PageTools
import time

class select(PageTools):
    zuzhi_ele = '[id="menucompany"]'
    tept1_ele = '[id="value4"]'
    tept2_ele = '[class="w-160px"] div[class="btn-group"] button[id="submit"]'

    chongzhi_ele = '[onclick="resetForm(this)"]'

    delete_button = '[title="删除用户"]'
    iframe_ele = '[id="modalIframe"]'
    mima_ele = '[id="verifyPassword"]'
    shanchu_ele = 'td[class="w-100px"] button[id="submit"]'

    update_ele = '[title="编辑用户"]'
    newname_ele = '[id="realname"]'
    checkpwd_ele = '[id="verifyPassword"]'
    baocun_ele = '[id="submit"]'

    success_ele = 'a[data-toggle="dropdown"]'
    def select_action(self, username):
        self.by_css(self.zuzhi_ele).click()
        time.sleep(1)
        self.by_css(self.tept1_ele).send_keys(username)
        time.sleep(1)
        self.by_css(self.tept2_ele).click()
        time.sleep(2)

    def delete_action(self, username):
        self.select_action(username=username)

        self.by_css(self.delete_button).click()
        time.sleep(1)
        self.driver.switch_to.frame(self.by_css(self.iframe_ele))
        self.by_css(self.mima_ele).send_keys('admin1234')
        time.sleep(1)
        self.by_css(self.shanchu_ele).click()
        time.sleep(1)
        self.driver.switch_to.default_content()
        time.sleep(2)

    def update_action(self,username, newname):
        self.select_action(username=username)

        self.by_css(self.update_ele).click()
        time.sleep(1)
        self.by_css(self.newname_ele).clear()
        time.sleep(1)
        self.by_css(self.newname_ele).send_keys(newname)
        time.sleep(1)
        self.by_css(self.checkpwd_ele).send_keys('admin1234')
        time.sleep(1)
        self.by_css(self.baocun_ele).click()
        time.sleep(2)

    def get_success_text(self):
        return self.by_css(self.success_ele).text